﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Database.Models
{
    [Table("Phong")]
    public sealed class Phong : BaseModel
    {
        public Phong()
        {
            Dois = new HashSet<Doi>();
        }

        public int Id { get; set; }

        [Required]
        [MaxLength(255)]
        public string Ma { get; set; }

        [Required]
        [MaxLength(255)]
        public string TenPhong { get; set; }

        [MaxLength(2000)]
        public string DienGiai { get; set; }

        public ICollection<Doi> Dois { get; set; }

        [NotMapped]
        public string DanhSachDoi
        {
            get
            {
                string content = string.Empty;
                if (Dois != null && Dois.Count > 0)
                {
                    foreach (var doi in Dois)
                    {
                        if (string.IsNullOrEmpty(content))
                        {
                            content = doi.TenDoi;
                        }
                        else
                        {
                            content = string.Concat(content, Environment.NewLine, doi.TenDoi);
                        }
                    }
                }
                return content;
            }
        }
    }
}